package com.lyon.custom.core;

import com.lyon.custom.common.agent.HttpAgent;

import java.util.Properties;

/**
 * @author LeeYan9
 * @since 2021-11-26
 */
public class LyonConfigServiceImpl implements ConfigService {

    /**
     * 长轮询客户端 ， 对请求、数据相关封装;
     */
    private ClientWorker clientWorker;
    private HttpAgent agent;
    /**
     * 长轮询， http请求，本地缓存
     */
    public LyonConfigServiceImpl(Properties properties) {
        this.agent = new ServerHttpAgent();
        this.clientWorker = new ClientWorker(properties, agent);
    }

    @Override
    public String[] getConfigData(String dataId, String group, long timeout) {
        return clientWorker.getConfigServer(group, dataId, timeout);
    }

    @Override
    public void addListener(String dataId, String group, Listener listener) {
        clientWorker.addListener(dataId, group, listener);
    }

}
